<template>
    <div class="login">
        <h1>登录中心</h1>
        <el-form :model="LoginFrom" ref="LoginFrom" label-width="100px" class="demo-ruleForm" label-position="top">
            <el-form-item label="" prop="userName" :rules="[{ required: true, message: '用户名不能为空'}]">
                <el-input placeholder="请输入用户名" type="userName" v-model="LoginFrom.userName" prefix-icon=""
                          auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item label="" prop="pwd" :rules="[{ required: true, message: '密码不能为空'}]">
                <el-input placeholder="请输入密码" type="password" v-model="LoginFrom.pwd" prefix-icon=""
                          auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button style="width: 300px" type="primary" v-loading.fullscreen.lock="fullscreenLoading"
                           @click="submitForm('LoginFrom')">提交
                </el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import {mapState, mapGetters, mapActions} from "vuex";
    export default {
        //注册组件
        components: {},
        computed: {
            ...mapState("account/xiaoma", ['isloginState']),
//            ...mapGetters("account/xiaoma", ['deleteVal'])
        },
        data() {
            return {
                LoginFrom: {userName: '', pwd: ''},
                fullscreenLoading: false
            };
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.fullscreenLoading = true;
                        this.login(this.LoginFrom);
                        setTimeout(() => {
                            this.fullscreenLoading = false;
                        }, 2000);
                    } else {
                        return false;
                    }
                });
            },

            ...mapActions("account/xiaoma", ['login','deleteVal'])
        }
        ,
        //生命周期==>挂载之前
        beforeMount() {

        },
        //生命周期==>数据更新完成后
        updated(){
            if(this.isloginState){
                this.$notify.error({
                    title: '错误',
                    message: '这是一条错误的提示消息',
                    duration:2000
                });
                this.deleteVal()
            }
        }
    };
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    .login {
        text-align: center;
        width: 300px;
        position: absolute;
        left: 50%;
        margin-top: 20%;
        transform: translateX(-50%);
    }
</style>
